<template>
  <div>
    <div class="zx_titel">搭建商信息</div>
    <div class="form_row">
      <el-form
        inline
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="160px"
        class="demo-ruleForm"
        size="small "
      >
        <el-form-item label="社会统一信用代码:" prop="creditCode">
          <el-input
            style="width: 250px"
            v-model="ruleForm.creditCode"
          ></el-input>
        </el-form-item>
        <el-form-item label="施工单位名称:" prop="constructionName">
          <el-input
            style="width: 250px"
            v-model="ruleForm.constructionName"
          ></el-input>
        </el-form-item>
        <el-form-item label="报馆负责人姓名:" prop="constructionDirector">
          <el-input
            style="width: 250px"
            v-model="ruleForm.constructionDirector"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="报馆负责人联系电话:"
          prop="constructionDirectorTel"
        >
          <el-input
            style="width: 250px"
            v-model="ruleForm.constructionDirectorTel"
          ></el-input>
        </el-form-item>
        <el-form-item label="现场负责人姓名:" prop="dutyElectWorkmanName">
          <el-input
            style="width: 250px"
            v-model="ruleForm.dutyElectWorkmanName"
          ></el-input>
        </el-form-item>
        <el-form-item label="现场负责人联系电话:" prop="dutyElectWorkmanTel">
          <el-input
            style="width: 250px"
            v-model="ruleForm.dutyElectWorkmanTel"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="but_warp">
      <!-- @click="hanldnext(3)" -->
      <el-button size="mini" @click="hanldnext(1)">上一步</el-button>
      <el-button size="mini" @click="hanldadd" type="danger"
        >保存并下一步</el-button
      >
    </div>
  </div>
</template>
<script>
import { organizetion_info, upalodapply, getOrganizetionInfo, stand_info } from "@/api/outfit/drawingadd";
import { getToken, setToken } from "@/utils/auth";
export default {
  name: 'step3',
  data() {
    return {
      infodata: {},
      standId: null,
      ruleForm: {
        constructionName: null,
        constructionDirector: null,
        creditCode: null,
        constructionDirectorTel: null,
        dutyElectWorkmanName: null,
        dutyElectWorkmanTel: null,
      },
      rules: {
        constructionName: [
          { required: true, message: "请输入施工单位名称", trigger: "blur" },
        ],
        constructionDirector: [
          { required: true, message: "请输入报馆负责人", trigger: "blur" },
        ],
        creditCode: [
          {
            required: true,
            message: "请输入社会统一信用代码",
            trigger: "blur",
          },
          {
            pattern: /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/,
            message: "请输入正确的社会统一信用代码",
            trigger: "blur",
          },
        ],
        constructionDirectorTel: [
          {
            required: true,
            message: "请输入报馆负责人联系电话",
            trigger: "blur",
          },
          {
            pattern: /^1[3|4|5|7|8][0-9]\d{8}$/,
            message: "请输入正确的电话号码",
            trigger: "blur",
          },
        ],
        dutyElectWorkmanName: [
          { required: true, message: "请输入值守工人姓名", trigger: "blur" },
        ],
        dutyElectWorkmanTel: [
          {
            required: true,
            message: "请输入值守工人联系电话",
            trigger: "blur",
          },
          {
            pattern: /^1[3|4|5|7|8][0-9]\d{8}$/,
            message: "请输入正确的电话号码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  // mounted() {
  //   this.infodata = JSON.parse(getToken("jd"));
  //   console.log(this.infodata);
  //   this.getOrganizetion();
  //   this.getStand();
  // },
  created() {
    this.infodata = JSON.parse(getToken("jd"));
    console.log(this.infodata);
    this.getOrganizetion();
    this.getStand();
  },
  methods: {
    hanldnext(index) {
      this.$emit("hanldnext", index);
    },
    getOrganizetion() {
      getOrganizetionInfo().then((res) => {
        this.ruleForm.constructionName = res.data.constructionName;
        this.ruleForm.creditCode = res.data.creditCode;
      });
    },
    getStand() {
      let stan = JSON.parse(getToken("stan"));
      this.standId = stan.id;
      if (stan) {
        this.ruleForm.constructionDirector = stan.constructionDirector;
        this.ruleForm.constructionDirectorTel = stan.constructionDirectorTel;
        this.ruleForm.dutyElectWorkmanName = stan.dutyElectWorkmanName;
        this.ruleForm.dutyElectWorkmanTel = stan.dutyElectWorkmanTel;
        console.log("stan", stan)
      }
    },
    hanldadd() {
      let stanId = getToken("stanId");
      if (stanId == null) {
        stanId = this.standId;
      }
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          let from = {
            id: stanId,
            constructionName: this.ruleForm.constructionName,
            creditCode: this.ruleForm.creditCode,
            constructionDirector: this.ruleForm.constructionDirector,
            constructionDirectorTel: this.ruleForm.constructionDirectorTel,
            dutyElectWorkmanName: this.ruleForm.dutyElectWorkmanName,
            dutyElectWorkmanTel: this.ruleForm.dutyElectWorkmanTel,
          };
          // if (this.infodata) {
          //   from.email =
          //     this.infodata.exhibitConstructionOrganizationInfo.email;
          //   from.constructionQualificationUrl =
          //     this.infodata.exhibitConstructionOrganizationInfo.constructionQualificationUrl;
          //   from.regPhone =
          //     this.infodata.exhibitConstructionOrganizationInfo.regPhone;
          //   from.loginDate =
          //     this.infodata.exhibitConstructionOrganizationInfo.loginDate;
          //   from.createTime =
          //     this.infodata.exhibitConstructionOrganizationInfo.createTime;
          //   from.isChecked =
          //     this.infodata.exhibitConstructionOrganizationInfo.isChecked;
          //   from.deleteFlag =
          //     this.infodata.exhibitConstructionOrganizationInfo.deleteFlag;
          //   from.isSpecial =
          //     this.infodata.exhibitConstructionOrganizationInfo.isSpecial;
          // }
          stand_info(from).then((res) => {
            if (res.code == 200) {
              console.log(res)
              let applyid = getToken("applyid");
                  let applyForm = {
                    id:applyid,
                    applyStep:3,
                    constructionName: this.ruleForm.constructionName
                  }
              setToken("stan", JSON.stringify(res.data));
              upalodapply(applyForm).then((res) => {
                this.hanldnext(3);
              })
            }
          });
          // organizetion_info(from).then((res) => {
          //   if (res.code == 200) {
          //     let applyid = getToken("applyid");
          //     let applyForm = {
          //       id:applyid,
          //       applyStep:3
          //     }
          //     upalodapply(applyForm).then((res) => {
          //       this.hanldnext(3);
          //     })
          //   }
          // });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style scoped>
.zx_titel {
  padding: 15px;
  font-size: 20px;
  font-weight: bold;
  border-bottom: 1px solid #e0e2e6;
}
.form_row {
  display: flex;
  justify-content: center;
  padding: 20px;
}
.but_warp {
  padding: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>